<template>
  <div class="home-container">
    <HeaderIndex
      :isReturnText="false"
      :isClose="false"
      :isService="name == legalAdviceText"
      ref="headerIndex"
    />
    <div class="nav" ref="nav">
      <div class="root-hint">
        <div class="root-manbig"></div>
        <div class="root-hint-text">
          <p>HI~，有什么可以帮您！</p>
          <p>法务智能机器人为您服务</p>
        </div>
      </div>
      <NavList @handleActive="handleActive" />
    </div>
    <div class="content">
      <LegalAdviceIndex v-show="name == legalAdviceText" />
      <IntelligentSearchIndex v-show="name == sintelligentSearchText" />
      <LegalServiceIndex v-show="name == legalServiceText" />
    </div>
  </div>
</template>

<script>
import HeaderIndex from "@/components/header";
import NavList from "@/components/nav";
import LegalAdviceIndex from "@/components/legalAdvice";
import IntelligentSearchIndex from "@/components/intelligentSearch";
import LegalServiceIndex from "@/components/legalService";
import { Cookie, getUrlParam, Toast } from "@/utils";
import { decrypt } from "@/utils/encryption.js"
import { getUserInfo } from "../../api";
export default {
  name: "Home",
  components: {
    HeaderIndex,
    NavList,
    LegalAdviceIndex,
    IntelligentSearchIndex,
    LegalServiceIndex,
  },
  data() {
    return {
      name: "legal-advice-container", //显示的容器
      legalAdviceText: "legal-advice-container", //法律咨询
      sintelligentSearchText: "sintelligent-search-container", //智能搜索
      legalReviewText: "legal-review-container", //法律审核
      legalServiceText: "legal-service-container", //法律服务
    };
  },
  async created(){
    // 提示加载中
    Toast.startLoading();
    const userInfo = (await getUserInfo()) || {};
    localStorage.setItem("userInfo",JSON.stringify(userInfo));
    //获取token
    this.initToken();
    
    //关闭提示加载中
    setTimeout(() => Toast.closeLoading(),500);
  },
  methods: {
    /**
     * 初始化token信息
     */
    initToken() {
      const token = getUrlParam("token");
      const mxSsoToken =
        getUrlParam("mx_sso_token") || localStorage.getItem("mx_sso_token");
      if (token) {
        Cookie.setCookie("aitalk_token_fl", token);
      } else if (!Cookie.getCookie("aitalk_token_fl")) {
        location.replace(
          `${decrypt(process.env.VUE_APP_JUMP_URL)}?mx_sso_token=${mxSsoToken}`
        );
      }

      if (mxSsoToken) {
        localStorage.setItem("mx_sso_token", mxSsoToken);
      }
    },

    /**
     * 切换导航栏，显示相应的内容
     * @param {*} name 容器名称
     */
    handleActive(name) {
      this.name = name;
    },
  },
};
</script>

<style lang="less" scoped>
@import url("~@/assets/styles/home/index.less");
</style>